package com.shouhuobao.take.mine;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.BaseFragment;
import com.shouhuobao.station.R;

import droid.frame.view.ViewPagerExt;

/**
 * Created by joker on 2017/8/16.
 * 我的二维码选择界面
 */
public class MyQRCodeActivity extends BaseActivity2 implements View.OnClickListener {

    ViewPagerExt mViewPager = null;
    BaseFragment mFragment1, mFragment2;
    private TextView mUserQRCodeTV, mExpressUserQRCodeTV;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.activity_my_qrcode);
        super.findViewById();
        getAppTitle().setCommonTitle("我的二维码");
        mViewPager = (ViewPagerExt) findViewById(R.id.viewpager);
        mUserQRCodeTV = (TextView) findViewById(R.id.user_qr_code_TV);
        mExpressUserQRCodeTV = (TextView) findViewById(R.id.express_user_qr_code_TV);
        mUserQRCodeTV.setOnClickListener(this);
        mExpressUserQRCodeTV.setOnClickListener(this);
        findViewById(R.id.shop_info_down_tv).setOnClickListener(this);

        mFragment1 = new UserQRCodeFragment();
        mFragment2 = new ExpressUserQRCodeFragment();

        mViewPager.setSupportScroll(false);
        mViewPager.setFragmentItems(getSupportFragmentManager(), mFragment1, mFragment2);
        mViewPager.setSupportScroll(true);
        mViewPager.setCurrentItem(0);
        mViewPager.setOffscreenPageLimit(2);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    mUserQRCodeTV.setBackgroundResource(R.drawable.my_qrcode_bg_selected_shape);
                    mExpressUserQRCodeTV.setBackgroundResource(R.drawable.my_qrcode_bg_shape);
                } else {
                    mUserQRCodeTV.setBackgroundResource(R.drawable.my_qrcode_bg_shape);
                    mExpressUserQRCodeTV.setBackgroundResource(R.drawable.my_qrcode_bg_selected_shape);
                }
                mViewPager.setCurrentItem(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        int position = mViewPager.getCurrentItem();
        switch (v.getId()) {
            //用户使用二维码
            case R.id.user_qr_code_TV:
                if (position==0){
                    return;
                }
                mViewPager.setCurrentItem(0);
                break;
            //快递员使用二维码
            case R.id.express_user_qr_code_TV:
                if (position==1){
                    return;
                }
                mViewPager.setCurrentItem(1);
                break;
            case R.id.shop_info_down_tv:
                startActivity(ShopInfoDownActivity.class);
                break;
        }
    }
}
